/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.engine.states;

import com.jme3.app.Application;
import com.jme3.app.state.AppStateManager;
import com.jme3.math.Vector3f;
import com.jme3.post.filters.RadialBlurFilter;

/**
 *
 * @author Carl
 */
public class MotionBlurAppState extends BaseAppState{

    public MotionBlurAppState(){
        
    }
    private RadialBlurFilter motionBlurFilter;
    private Vector3f lastFrameCameraDirection = new Vector3f();

    @Override
    public void initialize(AppStateManager stateManager, Application application){
        super.initialize(stateManager, application);
        motionBlurFilter = new RadialBlurFilter(0.7f, 1.25f);
        getAppState(PostFilterAppState.class).addFilter(motionBlurFilter);
    }

    @Override
    public void update(float lastTimePerFrame){
        super.update(lastTimePerFrame);
        Vector3f cameraDirection = mainApplication.getCamera().getDirection();
        float cameraDistanceDifference = (cameraDirection.subtract(lastFrameCameraDirection)).length();
        motionBlurFilter.setSampleStrength(cameraDistanceDifference * 35);
        lastFrameCameraDirection = cameraDirection;
    }
}
